package com.easy.customer.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.easy.common.bean.CustomerContact;
import com.easy.common.bean.CustomerInteraction;
import com.easy.common.service.ICustomerContactService;
import com.easy.common.service.ICustomerInteractionService;
import com.easy.customer.mapper.CustomerContactMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CustomerContactService implements ICustomerContactService {

    @Autowired
    CustomerContactMapper customerContactMapper;

    @Override
    public CustomerContact insert(CustomerContact customerContact) {
        customerContactMapper.insert(customerContact);
        return customerContact;
    }

    @Override
    public CustomerContact update(CustomerContact customerContact) {
        customerContactMapper.updateById(customerContact);
        return customerContact;
    }

    @Override
    public int delete(Integer id) {
        int num = customerContactMapper.deleteById(id);
        return num;
    }

    //设置主要联系方式
    @Override
    public int setPrimary(Integer id) {
        UpdateWrapper<CustomerContact> updateWrapper = new UpdateWrapper<>();
        updateWrapper.set("is_primary", 0);
        customerContactMapper.update(null, updateWrapper);

        UpdateWrapper<CustomerContact> setWrapper = new UpdateWrapper<>();
        setWrapper.set("is_primary", 1);
        setWrapper.set("id", id);
        return customerContactMapper.update(null, setWrapper);
    }
}
